<template>
  <div>
<!--    <div class="app-container">-->
<!--    <el-tabs type="card" @tab-click="handleClick" v-model="tabValue">-->
<!--      <el-tab-pane name="all" label="全部主体" lazy>-->
    <uc-table url="admin/inCheckRecords/getInCheckRecordsPage" ref="followUserTable" name="维保考核记录" table-border pageable :search-form="searchForm">
      <template slot="searchForm">
        <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
          <!--搜索输入框-->

          <el-form-item v-if="enterPriseHidden">
            <el-select v-model="searchForm.enterpriseId" placeholder="请选择责任企业" style="width: 100%" clearable  @clear="clearInput()">
              <el-option v-for="(item,index) in enterpriseDominantList" :key="index"  :value="item.ucId" :label="item.name"></el-option>
            </el-select>
          </el-form-item>
            <el-form-item>
                <el-select v-model="searchForm.source" placeholder="请选择考核类型" style="width: 100%" clearable  @clear="clearInput()">
                    <el-option :value="0" label="消防隐患"></el-option>
                    <el-option :value="2" label="维保工单"></el-option>
                    <el-option :value="3" label="维保任务"></el-option>
                </el-select>
            </el-form-item>
          <!--搜索按钮-->
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" class="filter-item" @click="handleSearch()">查询</el-button>
          </el-form-item>
        </el-form>
      </template>
      <template slot="columns">
        <el-table-column prop="enterpriseName" label="责任企业" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="enterpriseType" label="企业类型" align="left" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            {{scope.row.enterpriseType | enterpriseType}}
          </template>
        </el-table-column>
        <el-table-column prop="executorName" label="责任人" align="left" :show-overflow-tooltip="true"></el-table-column>
<!--        <el-table-column prop="type" label="考核类型" align="left" :show-overflow-tooltip="true"></el-table-column>-->
        <el-table-column prop="remark" label="详情" align="left" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="reportTime" label="上报时间" align="left" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                  {{scope.row.reportTime | dateFormat}}
              </template>
          </el-table-column>
          <el-table-column prop="type" label="考核类型" align="left" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                  {{scope.row.type | assessmentType}}
              </template>
          </el-table-column>
          <el-table-column prop="source" label="来源类型" align="left" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                  {{scope.row.source | checkRecordType}}
              </template>
          </el-table-column>
        <el-table-column prop="address" label="操作" width="270" align="left" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <!--编辑按钮-->
            <el-button  size="mini" icon="el-icon-edit" type="primary" @click="handleEdit(scope.row)" >编辑</el-button>
            <el-button size="mini" icon="el-icon-info" type="success" @click="handleInfo(scope.row)">详情</el-button>
            <el-button size="mini" type="danger" icon="el-icon-delete" :loading="deleteLoading" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </template>
    </uc-table>
<!--      </el-tab-pane>-->
<!--    </el-tabs>-->
<!--  </div>-->
    </div>
</template>

<script>
import UcTable from "@/components/UcTable/index.vue";
import {removeInCheckRecords} from "@/api/maintenanceCheckRecords";
import {getInEnterpriseDominantList} from "@/api/enterpriseDominant";


export default {

  name: "list",
  components: {UcTable},
  data(){
    return{
      searchForm:{
        deleted:false,
        enterpriseId: this.$route.query.enterpriseId
      },
      enterpriseDominantList:[],
      deleteLoading:false,
    }
  },
  created() {
    this.getInEnterpriseDominantList()
  },
  computed:{
    enterPriseHidden(){
      let roleCode = this.$store.getters.roleCode;
      return roleCode=="ADMIN"||roleCode=="XT-ADMIN"||roleCode=="ZD-ADMIN"||roleCode=="DD-ADMIN"||roleCode=="JW-ADMIN"
    }
  },
  methods: {
    handleSearch(){
      // console.log(val)
      this.$refs.followUserTable.getTableData(1)
    },
    getInEnterpriseDominantList(){
      getInEnterpriseDominantList({deleted:false}).then(res=>{
        this.enterpriseDominantList = res.data
      }).catch(error=>{

      })
    },
    handleEdit(val) {
      this.$router.push("/maintenance/checkRecordsEdit?ucId=" + val.ucId)
    },
    handleInfo(val) {
      this.$router.push("/maintenance/checkRecordsInfo?ucId=" + val.ucId)
    },
    clearInput(){
      //清除输入框
       this.searchForm.enterpriseId = null
      this.handleSearch()
    },
    handleDelete(val) {
      this.$confirm('您确定要执行删除' + val.name + '这条维保考核记录吗？', '提醒信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteLoading = true
        removeInCheckRecords(val).then(res => {
          this.deleteLoading = false
          this.$notify.success({
            title: '成功',
            message: "删除维保考核记录成功"
          })
          this.handleSearch(this.tabValue)
        }).catch(res => {
          this.deleteLoading = false
          this.$notify.error({
            title: '失败',
            message: res.msg
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
  }
}
</script>

<style
    scoped>

</style>